package work03;

import java.io.*;

public class Test03 {
    public static void main(String[] args) {
        File file = new File("D:/123.jpg");
        DataInputStream dis = null;
        DataOutputStream dos = null;
        try{
            if (file.exists()){
                dis = new DataInputStream(new FileInputStream(file));
                dos = new DataOutputStream(new FileOutputStream("D:/copy_123.jpg"));
                byte[] buffer = new byte[1024];
                int  temp = 0;
                while ((temp = dis.read(buffer)) != -1){
                    dos.write(buffer,0,temp);
                }
                dos.flush();
                System.out.println("文件拷贝成功！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
                try{
                    if (dos != null){
                        dos.close();
                        dos = null;
                    }
                    if (dis != null){
                        dis.close();
                        dis = null;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }

